package org.tulkas.l10n;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;

public class ResourceBundleControl extends ResourceBundle.Control {
	public static final String TULKAS_FORMAT = "tulkas_mixed";

	private String webRootPath;

	public ResourceBundleControl(String webRootPath) {
		this.webRootPath = webRootPath;
	}

	@Override
	public List<String> getFormats(String baseName) {
		return Arrays.asList(TULKAS_FORMAT);
	}

	@Override
	public ResourceBundle newBundle(String baseName, Locale locale,
			String format, ClassLoader loader, boolean reload)
			throws IllegalAccessException, InstantiationException, IOException {
		if (TULKAS_FORMAT.equals(format)) {
			return new TulkasResourceBundle(baseName, locale, loader, this);
		} else {
			throw new IllegalArgumentException("unknown format: " + format);
		}
	}

	@Override
	public long getTimeToLive(String baseName, Locale locale) {
		return TTL_NO_EXPIRATION_CONTROL;
	}

	@Override
	public boolean needsReload(String baseName, Locale locale, String format,
			ClassLoader loader, ResourceBundle bundle, long loadTime) {
		return false;
	}

	public String getWebRootPath() {
		return webRootPath;
	}
}